<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>借贷管理</el-breadcrumb-item>
      <el-breadcrumb-item>新增借贷</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-form :model="addloans" :rules="rules" ref="addloans" label-width="100px" class="demo-ruleForm">

        <el-row>
          <el-col :span="12">
            <el-form-item label="标名" prop="bidName">
              <el-input v-model="addloans.bidName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="风险等级" prop="riskLev">
              <el-select v-model="addloans.riskLev" placeholder="请选择">
                <el-option label="极低" value="1"></el-option>
                <el-option label="较低" value="2"></el-option>
                <el-option label="中等" value="3"></el-option>
                <el-option label="中高" value="4"></el-option>
                <el-option label="高级" value="5"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款总金额" prop="totalAmount">
              <el-input v-model="addloans.totalAmount"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年利率" prop="interest">
              <el-input v-model="addloans.interest"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="还款方式" prop="repayType">
              <el-select v-model="addloans.repayType" placeholder="请选择活动区域">
                <el-option label="一次性还款" value="0"></el-option>
                <el-option label="等额本息" value="1"></el-option>
                <el-option label="等额本金" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="期限类型" prop="termType">
              <el-radio-group v-model="addloans.termType">
                <el-radio label="天" value="0"></el-radio>
                <el-radio label="月" value="1"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款期限" prop="trem">
              <el-input v-model="addloans.trem"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="管理费月率" prop="manageRate">
              <el-input v-model="addloans.manageRate"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="逾期利率" prop="fineRate">
              <el-input v-model="addloans.fineRate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款类型" prop="loanType">
              <el-select v-model="addloans.loanType" placeholder="请选择活动区域">
                <el-option label="新增" value="0"></el-option>
                <el-option label="续贷" value="1"></el-option>
                <el-option label="资产处理" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="资金用途" prop="useFund">
              <el-input v-model="addloans.useFund"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="还款来源" prop="repaySouce">
              <el-input v-model="addloans.repaySouce"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否担保" prop="isGrt">
              <el-radio-group v-model="addloans.isGrt">
                <el-radio @click.native="shi" label="是" value="0"></el-radio>
                <el-radio label="否" value="1"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item>
          <el-button type="primary" @click="add()">立即创建</el-button>
          <el-button @click="resetForm('addloans')">重置</el-button>
        </el-form-item>
      </el-form>


      <el-dialog
        title="担保信息"
        :visible.sync="dialogVisible"
        width="70%">
        <el-form :model="ebankmginfo" :rules="ruless" ref="ebankmginfo" label-width="100px" class="demo-ruleForm">

          <el-row>
            <el-col :span="12">
              <el-form-item label="抵押类型:" prop="type">
                <el-radio-group v-model="ebankmginfo.type">
                  <el-radio label="无" value="0"></el-radio>
                  <el-radio label="房抵" value="1"></el-radio>
                  <el-radio label="车抵" value="2"></el-radio>
                  <el-radio label="民品抵" value="4"></el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="机构名称:" prop="fullName">
                <el-input v-model="ebankmginfo.fullName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="身份证号:" prop="idNum">
                <el-input v-model="ebankmginfo.idNum"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法人:" prop="legalPerson">
                <el-input v-model="ebankmginfo.legalPerson"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="ebankmginfo.email"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="tel">
                <el-input v-model="ebankmginfo.tel"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="上传借款资料" prop="resName">
                <el-upload
                  action=""
                  list-type="picture-card"
                  :on-preview="handlePictureCardPreview"
                  :on-remove="handleRemove">
                  <i class="el-icon-plus"></i>
                </el-upload>
                <el-dialog :visible.sync="dialogVisibles">
                  <img width="100%" :src="dialogImageUrl" alt="">
                </el-dialog>
              </el-form-item>
            </el-col>
          </el-row>


          <el-form-item>
            <el-button type="primary" @click="submitForm('ebankmginfo')">立即创建</el-button>
            <el-button @click="resetForm('ebankmginfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>


    </el-card>

  </div>
</template>

<script>
  export default {
    name: "Addborrow",
    data() {
      return {
        dialogVisible: false,
        dialogImageUrl: '',
        dialogVisibles: false,
        ebankmginfo:{
          type:"",
          fullName:"",
          idNum:"",
          legalPerson:"",
          email:"",
          tel:"",
        },
        addloans:{
          bidName:"",
          riskLev:"",
          totalAmount:"",
          interest:"",
          repayType:"",
          termType:"",
          trem:"",
          manageRate:"",
          fineRate:"",
          loanType:"",
          useFund:"",
          repaySouce:"",
          isGrt:"",
        },
        rules: {
          bidName: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            { min: 2, max: 8, message: '长度在 2 到 8 个字符', trigger: 'blur' }
          ],
          riskLev: [
            { required: true, message: '请选择风险类型', trigger: 'blur' },
          ],
          totalAmount: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            /*              { min: 2, max: 8, type: 'number', message: '金额必须为数字值', trigger: 'blur' }*/
          ],
          interest: [
            { required: true, message: '年利率不能为空', trigger: 'blur' },
          ],
          repayType: [
            { required: true, message: '请选择还款方式', trigger: 'blur' },
          ],
          termType: [
            { required: true, message: '请选择类型', trigger: 'blur' },
          ],
          trem: [
            { required: true, message: '请输入期限', trigger: 'blur' },
          ],
          manageRate: [
            { required: true, message: '请输入管理费月率', trigger: 'blur' },
          ],
          fineRate: [
            { required: true, message: '请输入逾期利率', trigger: 'blur' },
          ],
          loanType: [
            { required: true, message: '请选择借款类型', trigger: 'blur' },
          ],
          useFund: [
            { required: true, message: '请输入资金用途', trigger: 'blur' },
          ],
          repaySouce: [
            { required: true, message: '请输入还款来源', trigger: 'blur' },
          ],
          isGrt: [
            { required: true, message: '请选择是否担保', trigger: 'blur' },
          ],
        },
        ruless: {
          type: [
            { required: true, message: '请选择抵押类型', trigger: 'blur' },
          ],
          fullName: [
            { required: true, message: '请输入担保机构名称', trigger: 'blur' },
          ],
          idNum: [
            { required: true, message: '请输入身份证号', trigger: 'blur' },
          ],
          legalPerson: [
            { required: true, message: '请输入法人', trigger: 'blur' },
          ],
          email: [
            { required: true, message: '请输入邮箱', trigger: 'blur' },
          ],
          tel: [
            { required: true, message: '请输入电话号', trigger: 'blur' },
          ],
        }
      }
    },
    methods: {
      add:function(){
        debugger;
        this.$http.post("/finance_borrow/ebankloaninfo/addLoan",this.addloans).then((res)=>{
          if(res.data.success){
            alert("sd");
          }
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      shi:function(){
        this.dialogVisible=true;
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      }
    },
    filters: {

    },
    mounted() {
      this.searchUser();
      this.auth.token=sessionStorage.getItem("token");
    }
  }
</script>

<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
